/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package daos;

import entidades.Area;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author ARELLANO RODRIGUEZ
 */
@Stateless
@LocalBean
public class AreaDAO {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    @PersistenceContext EntityManager em;
    public void crear(Area area){
        em.persist(area);
    }
    public void actualizar(Area area){
        em.merge(area);
    }
    public void borrar(Area area){
        em.remove(area);
    }
    public List<Area> buscarTodas(){
        Query q=em.createNamedQuery("Area.findAll",Area.class);
        return q.getResultList();
    }
    public List<Area> buscarTodasSQL(){
        Query q=em.createNativeQuery("SELECT * FROM AREA", Area.class);
        return q.getResultList();
    }
    public List<Area> buscarPorNombre(String cadena){
        Query q=em.createQuery("SELECT a FROM Area a WHERE a.descripcionArea LIKE :cadena",Area.class);
        q.setParameter("cadena", "%"+cadena+"%");
        return q.getResultList();
    }
}
